//
//  AppDelegate.m
//  DoneTask
//
//  Created by NeiQuan on 16/7/27.
//  Copyright © 2016年 Mr-yuwei. All rights reserved.
//

#import "AppDelegate.h"
#import "YWNarViewController.h"
#import "HomePageController.h"
#import "AppDelegate+YWLaunchGuideView.h"
#import "AppDelegate+First.h"
#import "GoodListViewController.h"
#import "UMMobClick/MobClick.h"
#import "YWSystemWebViewController.h"
#import "JOJOWangSDK.h"
#import "JOJOWangDiamondConstants.h"
#import "AppDelegate+JPush.h"
#import "JPUSHService.h"
#import "YWHeader.h"
@interface AppDelegate ()

@end
@implementation AppDelegate
//百度推送：push.baidu.com
//18612116132
//yzrw2016
//duanyun18@sina.com
//411503Yang 开发者账号

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window=[[ UIWindow alloc] initWithFrame:[ UIScreen mainScreen].bounds];
    [self.window setBackgroundColor:[ UIColor whiteColor]];
    [self.window makeKeyAndVisible];
    
    GoodListViewController *rootVC=[[GoodListViewController alloc] init];
    self.window.rootViewController=[[ YWNarViewController alloc] initWithRootViewController:rootVC];
    [self YWmakeSplashViewGuide:nil];
    [self firstapplicationWillEnterForeground:application];
    
    
    //友盟统计
    [MobClick setLogEnabled:YES];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    [MobClick setAppVersion:version];
    UMConfigInstance.appKey = @"57a1b7dc67e58ef72000288e";
    UMConfigInstance.channelId = @"App Store";
    [MobClick startWithConfigure:UMConfigInstance];//配置以上参数后调用此方法初始化SDK！
    [MobClick setCrashReportEnabled:YES];
    [self  JpushApplication:application didFinishLaunchingWithOptions:launchOptions];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];//极光推送自定义消息体

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Jpushlogin:) name:kJPFNetworkDidLoginNotification object:nil];//注册成功
    //
    return YES;
}
-(void)Jpushlogin:(NSNotification *)notification{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"havedeviceToken" object:nil];
    NSLog(@"成功%@",[JPUSHService registrationID]);
    NSLog(@"成功");
    
}
- (void)applicationWillResignActive:(UIApplication *)application {
   
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
}
#pragma mark --private Method--每次进入前台都会重新加载方法
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self  firstapplicationWillEnterForeground:application ];
    });
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    
}

- (void)applicationWillTerminate:(UIApplication *)application {

}
#pragma mark - DianJoy offers wall connect notifications
- (void)offersWallConnectSuccess:(NSNotification *)notification
{

}
- (void)offersWallConnectFailed:(NSNotification *)notification
{
    
}
#pragma mark --透传传递数据
- (void)networkDidReceiveMessage:(NSNotification *)notification{

    NSDictionary *userInfo = [notification userInfo];
    NSString *dicstring=userInfo[@"content"];
    NSData *jsonData = [dicstring dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                         
                                                        options:NSJSONReadingMutableContainers
                         
                                                          error:&err];
    
    NSString *href_params=dic[@"href_params"];
    [JOJOWangSDK web_downloadApp:href_params result:^(BOOL isInstalled) { //判断是否下载过
        NSLog(@"result: %d", isInstalled);
    }];
}

@end
